<template>
	<view class="section-slider">
		<view class="slider-content">
			<jxs-slider v-model="slider" ref="slider" :height="7" :min="min" :max="max" :blockWidth="29" inactiveColor="#F1E6DF"
				activeColor="#FF442F" :moveHeight="100" :key="sliderKey"></jxs-slider>
		</view>
		<view class="slider-number">
			<view v-for="(item, index) in list" :key="index" class="number-text">{{item}}</view>
		</view>
		<view class="button-view">
			<view class="button-item" @click="onReset">重置</view>
			<view class="division"></view>
			<view class="button-item button-active" @click="onConfirm">确定</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: Array,
				default: () => []
			},
			start: {
				type: [String, Number],
				default: 0
			},
			end: {
				type: [String, Number],
				default: 0
			},
		},
		data() {
			return {
				slider: [0, 0],
				sliderKey: '',
				min: 0,
				max: 0
			};
		},
		beforeMount() {
			this.slider = [this.start || 0, this.end || 0]
			const list = JSON.parse(JSON.stringify(this.list))
			if (!list || !list.length) return
			this.min = list[0]
			this.max = list[list.length - 1]
		},
		methods: {
			onReset() {
				this.slider = [0, 0]
				this.$refs['slider'].updateValue(0, 0, false);
			},
			onConfirm() {
				const [start, end] = this.slider
				this.$emit('change', {
					start,
					end
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.section-slider {
		width: 100%;
		position: relative;

		.slider-number {
			width: 100%;
			padding: 20upx 40upx;
			@extend .row-between;

			.number-text {
				font-weight: 400;
				font-size: 25rpx;
				color: #B8ACA3;
			}
		}

		.slider-content {
			padding: 0 47upx;
		}

		.button-view {
			width: 100%;
			@extend .row;
			margin-top: 60upx;
			padding: 0 20upx;

			.button-item {
				width: calc(100% / 2 - 1px);
				height: 80upx;
				@extend .row;
				font-weight: 400;
				font-size: 29rpx;
				color: #B8ACA3;
			}

			.division {
				width: 1px;
				height: 33rpx;
				background: #F7E8E4;
			}

			.button-active {
				color: #FF2615;
			}
		}
	}
</style>